<h1>Basic View File Usage</h1>

<p>
    This section introduces fundamental concepts of view file management, using a basic installation of Trongate as a starting point.
</p>

<p>
    Upon installation, Trongate automatically loads the default 'welcome' module and its associated controller. Below is the initial structure of the 'Welcome' controller:
</p>

[code=php]&amp;lt;?php
class Welcome extends Trongate {

    /**
     * Renders the default 'welcome' webpage for public access.
     *
     * @return void
     */
    function index(): void {
        $data['view_module'] = 'welcome'; // Indicates the module containing the view file.
        $data['view_file'] = 'welcome'; // Specifies the base name of the target PHP view file.
        $this-&gt;template('public', $data); // Loads the 'welcome' view file within the public template.
    }
}
[/code]

<p>
    If the <code>index()</code> method is invoked, as specified by the 
    <a href="documentation/display/php_framework/understanding-routing/homepage-routing" target="_blank">default homepage routing configuration</a>, 
    it loads a template and passes a <code>$data</code> array containing a 'view_file' property.
</p>

<h2>Implementing a Custom Method</h2>

<p>
    To illustrate basic view file usage, we add a custom method to the 'Welcome' controller. Here's a simplified implementation of the 'greeting' method:
</p>

[code=php]function greeting() {
    $this-&gt;view("greeting");
}
[/code]

<h3>Introduction to the "View" Method</h3>

<p>
    To load view files, Trongate utilizes an internal method named 
    <span class="feature-ref" ref-path="class_reference/The_Trongate_Class">view()</span>.
</p>

<p>
    In the provided example, the <code>view()</code> 
    method is invoked with the argument 'greeting'. This triggers a search in the 'views' directory of the current module for a file named 'greeting.php'. 
    If found, the content of this file is rendered and displayed in the browser.
</p>

<div class="alert alert-warning">
    <p>
        The <span class="feature-ref" ref-path="class_reference/The_Trongate_Class">view()</span> method of Trongate accepts the name of the view file as an argument. 
        It is essential to <b>exclude</b> the file extension, such as '.php', from this argument.
    </p>
</div>

<p class="mt-3">
    With the addition of the <code>greeting()</code> method, the 'Welcome' controller will be extended as follows:
</p>

[code=php]&amp;lt;?php
class Welcome extends Trongate {

    /**
     * Renders the default 'welcome' webpage for public access.
     *
     * @return void
     */
    function index(): void {
        $data['view_module'] = 'welcome'; // Indicates the module containing the view file.
        $data['view_file'] = 'welcome'; // Specifies the base name of the target PHP view file.
        $this-&gt;template('public', $data); // Loads the 'welcome' view file within the public template.
    }

    function greeting() {
        $this-&gt;view("greeting");
    }
}
[/code]

<div class="alert alert-info">
    <p>
        <strong>Note:</strong> The example method named '<b>greeting</b>' omits elements such as type hinting, return types, 
        visibility modifiers (public, private, protected), and doc blocks for brevity. 
        These are essential for production code to ensure clarity, type safety, and proper documentation. 
        For additional information, please refer to the Trongate framework's 
        <a href="documentation/display/php_framework/basic-concepts/regarding-coding-style" target="_blank">coding style guide</a>.
    </p>
</div>

<h2>Creating a Simple View File</h2>

<p>
    After defining the method to load a view file, the next step is creating a new PHP file named 'greeting.php' 
    within the 'views' directory of the 'welcome' module. This file will contain basic HTML content for demonstration purposes. 
    For example:
</p>

[code=html]
&lt;h1&gt;Hello&lt;/h1&gt;
&lt;p&gt;It's nice to see you!&lt;/p&gt;
[/code]

<h2>Rendering the View File</h2>

<p>
    To render the view file in the browser, navigate to <code>BASE_URL/welcome/greeting</code>. 
    If the <code>greeting()</code> method and the corresponding 'greeting.php' view file are correctly implemented, 
    the browser will display output similar to the following:
</p>

<div class="text-center">
    <figure>
        <img src="images/78/greetingPZK7.png" alt="Screenshot demonstrating the rendering of a simple view file." style="width:100%">
        <figcaption>Screenshot demonstrating the rendering of a simple view file.</figcaption>
    </figure>
</div>

<h2>Conclusion</h2>

<p>
    This example provides a foundational overview of using view files within the Trongate framework. 
    By adding the <code>greeting()</code> method to the 'Welcome' controller, we demonstrate how Trongate's 
    <code>view()</code> method loads HTML content from a view file. 
    Remember to specify the view file name without the '.php' extension to ensure proper functionality.
</p>
